//
//  UIImageView+CQSplicedTemplateKit.m
//  CJUIKitDemo
//
//  Created by ciyouzen on 2017/9/11.
//  Copyright © 2017年 dvlproad. All rights reserved.
//

#import "UIImageView+CQSplicedTemplateKit.h"
#import <SDWebImage/SDWebImage.h>

@implementation UIImageView (CJImageAdjustGRViewUtil)

#pragma mark - 设置图片的基础接口
#pragma mark 设置图片：设置网络图片
/*
 *  为UIImageView设置网络图片
 *
 *  @param imageUrl             该网络图片的地址
 *  @param placeholderImage     占位图
 *  @param completed            设置完成的回调(返回的图片是将imageUrl得到的图片根据指定的方式处理后的图)
 */
- (void)CQSplicedTemplateKit_setImageWithUrl:(NSString *)imageUrl placeholderImage:(UIImage *)placeholderImage completed:(void(^ _Nullable)(UIImage * _Nullable bResultImage, NSURL * _Nullable imageURL))completedBlock {
#if CQSIMULATE_CQSplicedTemplateKit_IMAGE==1        // 如果之前有使用过模拟上传图片的，则要先去检查这个图片是不是网络图片，因为有可能是本地图片
    BOOL isNetworkImage = [imageUrl hasPrefix:@"http"];
    if (isNetworkImage == NO) {
        UIImage *image = [CQToolRequest imageFromLocalSimulateImageUrl:imageUrl];
        
        NSURL *imageURL = [NSURL URLWithString:imageUrl];
        !completedBlock ?: completedBlock(image, imageURL);
    } else {
        NSURL *mImageURL = [NSURL URLWithString:imageUrl];
        [self sd_setImageWithURL:mImageURL placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            !completedBlock ?: completedBlock(image, imageURL);
        }];
    }
#else
    NSURL *mImageURL = [NSURL URLWithString:imageUrl];
    [self sd_setImageWithURL:mImageURL placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        !completedBlock ?: completedBlock(image, imageURL);
    }];
#endif
}




@end
